const notcontroltype = [
  'wmpDetail',
  'listview',
  'pageheader',
  'dynamiclayout',
  'partlayout',
  'blank',
  'htmlArea',
  'button',
  'queryrelevance',
  'datarelevance',
  'autonumber', 'gridlist'
]
export function findFromVariable (
  frominfo,
  modelid,
  controlmodel,
  isdetailAssign
) {
  const fromVariableList = []
  frominfo.layoutitemlist[0].widgetForm.list.forEach(ee => {
    if (ee.type === 'gridPanel') {
      findPanelVariable(
        ee.columns[0].list,
        fromVariableList,
        ee.title,
        modelid,
        controlmodel,
        isdetailAssign
      )
    } else if (ee.type === 'tabs') {
      ee.options.panelist.forEach(tab => {
        findPanelVariable(
          tab.columns[0].list,
          fromVariableList,
          tab.title,
          modelid,
          controlmodel,
          isdetailAssign
        )
      })
    } else if (ee.type === 'collapse') {
      ee.options.panelist.forEach(tab => {
        findPanelVariable(
          tab.columns[0].list,
          fromVariableList,
          tab.title,
          modelid,
          controlmodel,
          isdetailAssign
        )
      })
    }
  })
  return fromVariableList
}
export function findPanelVariable (
  list,
  fromVariableList,
  title,
  modelid,
  controlmodel,
  isdetailAssign
) {
  list.forEach(element => {
    if (
      (isdetailAssign !== true || modelid === undefined) &&
      element.model !== controlmodel &&
      notcontroltype.indexOf(element.type) < 0
    ) {
      fromVariableList.push({
        value: element.options.filed,
        title: title + '-' + element.title
      })
    } else if (element.type === 'partlayout') {
      findPanelVariable(
        element.list,
        fromVariableList,
        title + '-' + element.title
      )
    } else if (
      element.type === 'listview' &&
      element.options.controlId === modelid
    ) {
      findListviewVariable(
        element.options.columns,
        fromVariableList,
        title + '-' + element.title,
        element,
        controlmodel
      )
    }
  })
}
export function findListviewVariable (
  list,
  fromVariableList,
  title,
  listview,
  controlmodel
) {
  list.forEach(element => {
    if (
      element.model !== controlmodel &&
      notcontroltype.indexOf(element.type) < 0
    ) {
      fromVariableList.push({
        value: listview.options.controlId + '.' + element.dataIndex,
        title: title + '-' + element.title
      })
    }
  })
}
export function findAllFromVariable (frominfo) {
  const fromVariableList = []
  frominfo.layoutitemlist[0].widgetForm.list.forEach(ee => {
    if (ee.type === 'gridPanel') {
      findAllPanelVariable(
        ee.columns[0].list,
        fromVariableList,
        ee.title
      )
    } else if (ee.type === 'tabs') {
      ee.options.panelist.forEach(tab => {
        findAllPanelVariable(
          tab.columns[0].list,
          fromVariableList,
          tab.title
        )
      })
    } else if (ee.type === 'collapse') {
      ee.options.panelist.forEach(tab => {
        findAllPanelVariable(
          tab.columns[0].list,
          fromVariableList,
          tab.title
        )
      })
    }
  })
  return fromVariableList
}
export function findAllPanelVariable (list,
  fromVariableList,
  title) {
  list.forEach(element => {
    if (notcontroltype.indexOf(element.type) < 0) {
      fromVariableList.push({
        value: element.options.filed,
        title: title + '-' + element.title
      })
    } else if (element.type === 'partlayout') {
      findAllPanelVariable(
        element.list,
        fromVariableList,
        title + '-' + element.title
      )
    } else if (element.type === 'listview') {
      findAllListviewVariable(
        element.options.columns,
        fromVariableList,
        title + '-' + element.title,
        element
      )
    }
  })
}
export function findAllListviewVariable (
  list,
  fromVariableList,
  title,
  listview
) {
  list.forEach(element => {
    if (notcontroltype.indexOf(element.type) < 0) {
      fromVariableList.push({
        value: listview.options.controlId + '.' + element.dataIndex,
        title: title + '-' + element.title
      })
    }
  })
}
